import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue';
import company from "./modules/company";

import NProgress from 'nprogress';
import 'nprogress/nprogress.css';

Vue.use(VueRouter);

import Layout from "@/layout";

export const constantRoutes = [
    {
        path: '/',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/home',
                component: Home
            }
        ]
    },
    //404、401等固定的路由
    {
        path: '/about',
        name: 'About',
        component: () => import('@/views/About.vue')
    }
];

const asyncRoutes = [
    company
]

const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes: constantRoutes.concat( asyncRoutes )
});

NProgress.configure({ showSpinner: false }) //进度条

router.beforeEach(async (to, from, next) => {
    // 加载进度条
    NProgress.start();
    window.document.title = to.meta.title||"YHW"; //配置网页的标题；
    next();
})

router.afterEach(() => {
    //document.documentElement.scrollTop = document.body.scrollTop = 0;
    // 进度条结束
    NProgress.done();

})

export default router
